// pages/Account_settings/Account_settings.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickName: null,
    parentName: null,
    parentMobile: null,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button-type.getUserInfo')
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.setData({ 
      nickName: app.globalData.appUser.userInfo.nickName,
      parentName: app.globalData.appUser.userInfo.parentName,
      parentMobile: app.globalData.appUser.userInfo.parentMobile
    })
  },
  formSubmit: function (e) {
    var nickName = e.detail.value.nickName;
    var parentName = e.detail.value.parentName;
    var parentMobile = e.detail.value.parentMobile;
    let that = this;
    wx.request({
      url: app.httpUrl + '/user/updateUserInfo',
      header: {
        'xcx-xtoken': app.globalData.openid,
        'content-type': 'application/json' // 默认值
      },
      method: "POST",
      data: {
        nickName: nickName,
        parentName: parentName,
        parentMobile: parentMobile
      },
      success: (res) => {
        if (res.data.code != '000') {
          wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 });
        } else {
          wx.showToast({ title: '修改成功', icon: 'success', duration: 2000 });
          app.globalData.appUser.userInfo.nickName = nickName;
          app.globalData.appUser.userInfo.parentName = parentName;
          app.globalData.appUser.userInfo.parentMobile = parentMobile;
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})